<?php
/**
 *用户调用类
 *@author sulwan@126.com
 *@date 2009-11-20
 */

 class App extends Application{

 public function __construct() {
    parent::__construct();
 }


/**
 *保存用户APP账户与密码
 */
public function saveApp($data) {
	$data = array_map('mysql_escape',$data);
	$sql = "INSERT INTO `#happy_app`(`".implode("`,`",array_keys($data))."`)VALUES('".implode("','",array_values($data))."')";
	$id = $this->_db->execute($sql);
	return $id;
}

/**
 *获取用户应用
 */
public function getApp($page,$num,$findkey='',$order='id',$fields='*') {
	$numrows = intval($num);
	$page = (intval($page) > 0) ? intval($page) : 1;
	$offset = ($page -1) * $numrows;
	#
	$where = is_array($findkey) ? implode(' AND ', $findkey) : $findkey;
	$where = empty ($where) ? '' : ' WHERE ' . $where;
	#
	$orderby = ($orderby == '+') ? 'ASC' : 'DESC';
	$order = empty ($order) ? '' : (' ORDER BY ' . $order . ' ' . $orderby);
	#
	if(!empty($numrows)) {
		$limits =  '  LIMIT '.$offset.','.$numrows;
	}
	#
	$sql = 'SELECT ' . $fields . ' FROM ' . '#happy_app';
	$sql .= $where . $order . $limits;
	#
	$rs = $this->_db->getAll($sql);
	return $rs;
}

/**
 *应用查询
 */
 public function getAppRow($uid,$app) {
	 $sql = 'SELECT * FROM ' . '#happy_app where uid = '.intval($uid).' AND app = \''.$app.'\'' ;
	 return $this->_db->getRow($sql);
 }

}
 ?>